<template>
	<view>
		<scroll-view scroll-y class="page">
			
			
			  <!-- 头部logo-->
		  <view class="UCenter-bg">
			<image src="https://ylb123.oss-cn-hangzhou.aliyuncs.com/app/logo-1024-square.png" 
				class="png round animation-slide-right margin-bottom-sm" 
				mode="scaleToFill" :style="[{animationDelay: '0.1s'}]"></image>
		    <image src="https://ylb123.oss-cn-hangzhou.aliyuncs.com/app/wave.gif" mode="scaleToFill" class="gif-wave"></image>
		  </view>
		  <view class="padding flex text-center text-grey bg-white shadow-warp">
		    <view class="flex flex-sub flex-direction solid-right animation-slide-top" :style="[{animationDelay: '0.2s'}]">
		      <view class="text-xl text-orange" style="height: 36upx; line-height: 36upx;">{{userAccountHide}}</view>
			  <view class="margin-top-sm" style="height: 20upx; line-height: 20upx;">
				  <text class="cuIcon-people margin-right-xs"></text> 账号
			  </view>
		    </view>
		    
		    <view class="flex flex-sub flex-direction animation-slide-top" :style="[{animationDelay: '0.2s'}]">
				<view v-if="userIdentity=='0'"
					class="text-xl text-green"
					style="height: 36upx; line-height: 36upx;">
					{{(cusIsVip=='Y' || cusIsVip=='y')?cusVipLevelTitle:'非会员'}}
				</view>
				<view v-if="userIdentity=='1'"
					class="text-xl text-green"
					style="height: 36upx; line-height: 36upx;">
					护士
				</view>
				<view v-if="userIdentity=='2'"
					class="text-xl text-green"
					style="height: 36upx; line-height: 36upx;">
					医生
				</view>
				
				<!-- <view class="text-xl text-green">
					<text v-if="userIdentity=='0'">
						{{(cusIsVip=='Y' || cusIsVip=='y')?cusVipLevelTitle:'非会员'}}
					</text>
					<text v-if="userIdentity=='1'">护士</text>
					<text v-if="userIdentity=='2'">医生</text>
				</view> -->
				
				<view v-if="userIdentity=='0'"
					class="margin-top-sm"
					style="height: 20upx; line-height: 20upx;">
					<text v-if="cusVipStartTimeShort && cusVipEndTimeShort"
						class="cuIcon-time margin-right-xs"></text>
					<text v-if="!(cusVipStartTimeShort && cusVipEndTimeShort)"
						class="cuIcon-news margin-right-xs"></text>
					{{(cusVipStartTimeShort && cusVipEndTimeShort)?(cusVipStartTimeShort + '至' + cusVipEndTimeShort):'身份'}}
				</view>
				<view v-if="userIdentity=='1' || userIdentity=='2'"
					class="margin-top-sm"
					style="height: 20upx; line-height: 20upx;">
					<text class="cuIcon-news margin-right-xs"></text> 身份
				</view>
				
				<!-- <view class="margin-top-sm">
					<text v-if="userIdentity=='0' && (cusVipStartTimeShort && cusVipEndTimeShort)">
						<text class="cuIcon-time margin-right-xs"></text>
						{{cusVipStartTimeShort}}至{{cusVipEndTimeShort}}
					</text>
					
					<text v-if="userIdentity=='1' || userIdentity=='2'"
						class="cuIcon-news margin-right-xs">身份</text>
				</view> -->
		    </view>
		  </view>
		  
		  <!-- 列表list-->
		  <view class="cu-list menu card-menu margin-top-xl margin-bottom-xl shadow-lg radius">
			
		    <!-- 
			<view class="cu-item arrow animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
			  <view class="content" >
			    <text class="cuIcon-favorfill text-yellow"></text>
			    <text class="text-grey">体检报告</text>
			  </view>
			</view>
			<view class="cu-item arrow animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
			  <view class="content" >
			    <text class="cuIcon-favorfill text-yellow"></text>
			    <text class="text-grey">诊疗记录</text>
			  </view>
			</view> -->
			
			
			<view v-if="userIdentity=='0'"
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.2s'}]"
				@tap="toRecharge()">
			  <view class="content">
			    <text class="iconfont cyIcon-chongzhi2 margin-right-sm" style="color: #ffc444;"></text>
			    <text class="text-666666">会员充值</text>
			  </view>
			</view>
			
		    <view v-if="userIdentity=='0'" 
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.25s'}]"
				@tap="toConsumeRecord()">
		      <view class="content">
		        <text class="iconfont cyIcon-jilu margin-right-sm" style="color: #fe7c66;"></text>
		        <text class="text-666666">消费记录</text>
		      </view>
		    </view>
			
			<view v-if="userIdentity=='0'"
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.25s'}]"
				@tap="toJiankang()">
			  <view class="content">				
			    <!-- <view style="color: #fe7c66;"></view> -->
				<image src="../../static/health.png"></image>
			    <text class="text-666666">健康档案</text>
			  </view>
			</view>
			
			<view v-if="userIdentity=='0'"
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.3s'}]"
				@tap="toMemberEdit()">
			     <view class="content">
				    <text class="iconfont cyIcon-gerenziliao-tongxunlu-05 margin-right-sm" style="color: #43e38d;"></text>
					<text class="text-666666">个人资料</text>
			    </view>
			</view>
			
			<view v-if="userIdentity=='0'"
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.35s'}]" 
				@tap="toUrgencyLink()">
				<view class="content" >
				    <text class="iconfont cyIcon-lianxiren margin-right-sm" style="color: #2eafff;"></text>
					<text class="text-666666">紧急联系人</text>
				</view>
			</view>
			
			<view v-if="userIdentity!='0'"
				class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.35s'}]" 
				@tap="toDnOperCallList()">
				<view class="content" >
				    <text class="iconfont cyIcon-lianxiren margin-right-sm" style="color: #2eafff;"></text>
					<text class="text-666666">呼叫处理</text>
					<text class="text-red" style="float:right;">{{dnNoReadCallCount!='0'?(dnNoReadCallCount+'条未读'):''}}</text>
				</view>
			</view>
			
			<view class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.4s'}]"
				@tap="toAboutUs()">
			     <view class="content">
				    <text class="iconfont cyIcon-gongsi margin-right-sm" style="color: #fd7192;"></text>
					<text class="text-666666">公司简介</text>
			    </view>
			</view>
			
			<view class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.45s'}]"
				@tap="toLinkUs()">
			     <view class="content">
				    <text class="iconfont cyIcon-dianhualianxiwo margin-right-sm" style="color: #7f7ffb;"></text>
					<text class="text-666666">联系我们</text>
			    </view>
			</view>
			
			<view class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.5s'}]"
				@tap="toServiceAgreement()">
			     <view class="content">
				    <text class="iconfont cyIcon-xieyi margin-right-sm" style="color: #ab3ac7;"></text>
					<text class="text-666666">隐私&服务</text>
			    </view>
			</view>
			
			<view class="cu-item animation-slide-bottom"
				:style="[{animationDelay: '0.55s'}]">
			     <view class="content">
				    <text class="iconfont cyIcon-bushubanben_mianxing margin-right-sm" style="color: #4caf50;"></text>
					<text class="text-666666">软件版本</text>
					<text class="text-gray" style="float:right;">{{appVersion?(appVersion):''}}</text>
			    </view>
			</view>
		   
			<view class="cu-item arrow animation-slide-bottom" 
				:style="[{animationDelay: '0.6s'}]" 
				hover-class="none"
				@tap="loginOut()">
				<view class="content" >
				    <text class="iconfont cyIcon-tuichu margin-right-sm" style="color: #1cbbb4;"></text>
					<text class="text-666666">安全退出</text>
				</view>
			</view>
			<view class="cu-item arrow animation-slide-bottom"
				:style="[{animationDelay: '0.6s'}]" 
				hover-class="none"
				@tap="loginOutAndDesdroy()">
				<view class="content" >
				    <text class="iconfont cyIcon-tuichu margin-right-sm" style="color: #3cmmb4;"></text>
					<text class="text-666666">注销账号</text>
				</view>
			</view>
			
		  </view>
		  <view class="cu-tabbar-height"></view>
		</scroll-view>
	</view>
</template>

<script>
	import {
		APP_VERSION,
		APP_MUST_PERMISSION_STATUS,
		
		USER_HAS_LOGIN,
		USER_ACCOUNT,
		USER_IDENTITY,
		USER_TOKEN,
		
		CUS_IS_VIP,
		CUS_VIP_LEVEL_ID,
		CUS_VIP_LEVEL_TITLE,
		CUS_VIP_START_TIME,
		CUS_VIP_END_TIME,
		COMPANY_KEFU_PHONE1,
	} from "@/common/util/constants"
	import api from '@/api/api'
	import moment from 'moment'
	
	export default {
		name: "people",
		props:{
			pageCur: String,
		},
		data() {
			return {
				userHasLogin: 0,
				userAccount: '',
				userAccountHide: '',
				userIdentity: '',
				userIdentityName: '',
				cusIsVip: 'N',
				cusVipLevelId: '',
				cusVipLevelTitle: '',
				cusVipStartTime: '',
				cusVipStartTimeShort: '',
				cusVipEndTime: '',
				cusVipEndTimeShort: '',
				
				appVersion: '',
				
				personalList:{
				  avatar:'',
				  realname:'',
				  username:'',
				  post:''
				},
				positionUrl:'/sys/position/list',
				departUrl:'/sys/user/userDepartList',
				userUrl:'/sys/user/queryById',
				postUrl:'/sys/position/queryByCode',
				userId:'',
				id:'',
				
				dnNoReadCallCount: '0',	//医护-未读的呼叫数量
			};
		},
		watch: {
			pageCur: {
				immediate: true,
				handler() {
				    this.userId=this.$store.getters.userid;
					this.load()
				},
			},
		},
		created() {
			uni.pageScrollTo({
			    scrollTop: 0,
			    duration: 0
			});
			this.getAppVersion()
			this.getUserInfo();
		},
		methods: {
			//公司简介
			toAboutUs(){
				uni.navigateTo({
					url: '/pages/singles/about-us'
				})
			},
			//联系我们
			toLinkUs(){
				uni.navigateTo({
					url: '/pages/singles/link-us'
				})
			},
			// 健康档案
			toJiankang(){
				uni.navigateTo({
					url: '/pages/member-health-record/list'
				})
			},
			// 用户信息
			getUserInfo(){
				let that = this
				that.userHasLogin = uni.getStorageSync(USER_HAS_LOGIN)
				if(that.userHasLogin!='1'){
					that.$tip.toast('登录超时');
					let app_must_permission_status = uni.getStorageSync('APP_MUST_PERMISSION_STATUS')
					uni.clearStorageSync();
					uni.setStorageSync('APP_MUST_PERMISSION_STATUS', app_must_permission_status)
					setTimeout(function() {
						uni.redirectTo({
						    url: '/pages/login/login'
						});
					}, 500);
					return false
				}
				
				that.userIdentity = uni.getStorageSync(USER_IDENTITY)
				//用户-身份(0-会员,1-护士,2-医生)
				if(that.userIdentity=='0'){
					that.userIdentityName = '会员'
					
					//在会员最新信息读取没有完成前，先用缓存记录填充
					that.cusIsVip = uni.getStorageSync(CUS_IS_VIP)
					that.cusVipLevelId = uni.getStorageSync(CUS_VIP_LEVEL_ID)
					that.cusVipLevelTitle = uni.getStorageSync(CUS_VIP_LEVEL_TITLE)
					that.cusVipStartTime = uni.getStorageSync(CUS_VIP_START_TIME)
					that.cusVipEndTime = uni.getStorageSync(CUS_VIP_END_TIME)
					
					if(that.cusVipStartTime){
					   that.cusVipStartTimeShort = moment(that.cusVipStartTime).format('YYYY/M/D')
					}
					if(that.cusVipEndTime){
					   that.cusVipEndTimeShort = moment(that.cusVipEndTime).format('YYYY/M/D')
					}
					
					that.getMemberNewestInfo()
				}else if(that.userIdentity=='1'){
					that.userIdentityName = '护士'
					//[医护]呼叫未读数量
					that.loadNoReadCallCount()
				}else if(that.userIdentity=='2'){
					that.userIdentityName = '医生'
					//[医护]呼叫未读数量
					that.loadNoReadCallCount()
				}else{
					that.userIdentityName = '-'
				}
				
				that.userAccount = uni.getStorageSync(USER_ACCOUNT)
				//账号隐藏中间4位
				if(that.userAccount.length==11){
					that.userAccountHide = that.userAccount.substring(0,3) + '****' + that.userAccount.substring(7)	
				}else{
					that.userAccountHide = that.userAccount
				}
			},
			//获取会员最新信息, 然后更新到本地缓存
			getMemberNewestInfo(){
				let that = this
				that.$http.get("/vip/vipmember/queryByToken",{}).then(res=>{
					if(res.data.success){
						/*
							address: "汉中市中心1号院100室"
							city: "610103"
							endtime: "2023-01-13"
							id: "1475023397223403522"
							identity: "52345234523453452"
							isVip: "Y"
							phone: "17189211859"
							realname: "欧阳认知"
							sex: 1
							startTime: "2022-01-12"
							tuijiancode: "tjm999"
							username: "行者"
							vipLevelId: 3
							vipLevelTitle: "尊享会员"
							yuyuecount: "22"
						*/
					   let jsonData = res.data.result
					   
					   uni.setStorageSync(CUS_IS_VIP, jsonData.isVip?jsonData.isVip:'N');
					   uni.setStorageSync(CUS_VIP_LEVEL_ID, jsonData.vipLevelId?jsonData.vipLevelId:'');
					   uni.setStorageSync(CUS_VIP_LEVEL_TITLE, jsonData.vipLevelTitle?jsonData.vipLevelTitle:'');
					   uni.setStorageSync(CUS_VIP_START_TIME, jsonData.startTime?jsonData.startTime:'');
					   uni.setStorageSync(CUS_VIP_END_TIME, jsonData.endtime?jsonData.endtime:'');
					   
					   that.cusIsVip = jsonData.isVip?jsonData.isVip:'N'
					   that.cusVipLevelId = jsonData.vipLevelId?jsonData.vipLevelId:''
					   that.cusVipLevelTitle = jsonData.vipLevelTitle?jsonData.vipLevelTitle:''
					   that.cusVipStartTime = jsonData.startTime?jsonData.startTime:''
					   that.cusVipEndTime = jsonData.endtime?jsonData.endtime:''
					   
					   if(that.cusVipStartTime){
						   that.cusVipStartTimeShort = moment(that.cusVipStartTime).format('YYYY/M/D')
					   }
					   if(that.cusVipEndTime){
						   that.cusVipEndTimeShort = moment(that.cusVipEndTime).format('YYYY/M/D')
					   }
					}else{
					}
				}).catch(err => {
				});
			},
			// 退出登录
			loginOut(){
				uni.showModal({
				    title: '',
				    content: '确认退出登录?',
				    success: function (res) {
				        if (res.confirm) {
				            let app_must_permission_status = uni.getStorageSync('APP_MUST_PERMISSION_STATUS')
				            uni.clearStorageSync();
				            uni.setStorageSync('APP_MUST_PERMISSION_STATUS', app_must_permission_status)
				            uni.redirectTo({
				                url: '/pages/login/login'
				            });
				        } else if (res.cancel) {
				            
				        }else{
						}
				    }
				});
			},
			//注销账号
			loginOutAndDesdroy(){
				uni.showModal({
				    title: '',
				    content: '确认注销?',
				    success: function (res) {
				        if (res.confirm) {
				            let app_must_permission_status = uni.getStorageSync('APP_MUST_PERMISSION_STATUS')
				            uni.clearStorageSync();
				            uni.setStorageSync('APP_MUST_PERMISSION_STATUS', app_must_permission_status)
				            
							let that = this
							that.$http.get("/vip/vipmember/delete",{}).then(res=>{
								if(res.data.success){
									uni.redirectTo({
									    url: '/pages/login/login'
									})
								}
							})
							uni.redirectTo({
							    url: '/pages/login/login'
							})
							
				        } else if (res.cancel) {
				            
				        }else{
						}
				    }
				});
			},
			//[医护]未读的呼叫记录总数量
			loadNoReadCallCount(){
				let that = this
				that.$http.get("/hujiao/yjhj/queryMsgById", {}).then(res=>{
					if(res.data.success){
						that.dnNoReadCallCount = res.data.result.unreadCount
					}else{
					}
				}).catch(err => {
				});
			},
			//获取APP版本
			getAppVersion(){
				this.appVersion = uni.getStorageSync(APP_VERSION)
			},
			//去服务协议
			toServiceAgreement(){
				uni.navigateTo({
					url: '/pages/singles/service-agreement'
				})
			},
			load(){
				if(!this.userId){
					
					return;
				}
				this.$http.get(this.userUrl,{params:{id:this.userId}}).then(res=>{
					 if (res.data.success) {
						let perArr = res.data.result
				        let avatar=(perArr.avatar && perArr.avatar.length > 0)? api.getFileAccessHttpUrl(perArr.avatar):'/static/avatar_boy.png'
						this.personalList.avatar =avatar
						this.personalList.realname = perArr.realname
						this.personalList.username = perArr.username
						this.personalList.depart = perArr.departIds
					    this.getpost(perArr.post)
						
						this.personalList.username = '186****1234'
					}
				}).catch(err => {
				});
				
			},
			getpost(code){
				if(!code||code.length==0){
					this.personalList.post='员工'
					return false;
				}
				this.$http.get(this.postUrl,{params:{code:code}}).then(res=>{
					 if (res.data.success) {
						this.personalList.post=res.data.result.name
						this.personalList.post='会员'
					}
				}).catch(err => {
				});
				
			},
			//会员充值 
			toRecharge(){
				if(this.userIdentity!='0'){
					this.$tip.toast('仅对会员开放');
					return false;
				}
				uni.navigateTo({
					url: '/pages/recharge/recharge'
				})
			},
			//消费记录
			toConsumeRecord(){
				if(this.userIdentity!='0'){
					this.$tip.toast('仅对会员开放');
					return false;
				}
				uni.navigateTo({
					url: '/pages/xiaofei/xiaofei',
				})
				//this.$tip.toast("财务系统对接中...")
				// uni.showLoading({
				// 	title: '审批中..',
				// 	mask: true,
				// })
				// setTimeout(function() {
				// 	uni.showModal({
				// 		title: '安全提示',
				// 		content: '预约成功(请勿重复申请)!\n随后平台客服将与您本人联系，了解进度或消费情况欢迎致电\n' + COMPANY_KEFU_PHONE1,
				// 		confirmText: '确定',
				// 		showCancel: false,
				// 		success: (showResult) => {
				// 			if (showResult.confirm) {
								
				// 			}
				// 		}
				// 	})
				// 	uni.hideLoading()
				// }, 5000);
			},
			//紧急联系人
			toUrgencyLink(){				
				if(this.userIdentity!='0'){
					this.$tip.toast('仅对会员开放');
					return false;
				}
				uni.navigateTo({
					url: '/pages/user/urgency-link'
				})
			},
			//[医护]呼叫处理
			toDnOperCallList(){
				if(this.userIdentity=='0'){
					this.$tip.toast('仅对医护开放');
					return false;
				}
				this.dnNoReadCallCount = '0'
				uni.navigateTo({
					url: '/pages/doctor-nurse/oper-call-list'
				})
			},
			//个人资料
			toMemberEdit(){
				if(this.userIdentity!='0'){
					this.$tip.toast('仅对会员开放');
					return false;
				}
				
				this.userHasLogin = uni.getStorageSync(USER_HAS_LOGIN)
				if(this.userHasLogin!='1'){
					this.$tip.toast('请登录');
					let app_must_permission_status = uni.getStorageSync('APP_MUST_PERMISSION_STATUS')
					uni.clearStorageSync();
					uni.setStorageSync('APP_MUST_PERMISSION_STATUS', app_must_permission_status)
					setTimeout(function() {
						uni.redirectTo({
						    url: '/pages/login/login'
						});
					}, 500);
					return false
				}
				
				uni.navigateTo({
					url: '/pages/user/member-edit'
				})
			},
		}
	}
</script>

<style>
.UCenter-bg {
  background-image: url('https://ylb123.oss-cn-hangzhou.aliyuncs.com/app/mine-top-bg-1.png');
  background-size: cover;
  height: 240rpx;
  display: flex;
  justify-content: center;
  padding-top: 30rpx;
  overflow: hidden;
  position: relative;
  flex-direction: column;
  align-items: center;
  color: #fff;
  font-weight: 300;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.3);
}

.UCenter-bg text {
  opacity: 0.8;
}

.UCenter-bg image {
  width: 150rpx;
  height: 150rpx;
}

.UCenter-bg .gif-wave{
  position: absolute;
  width: 100%;
  bottom: 0;
  left: 0;
  z-index: 99;
  mix-blend-mode: screen;  
  height: 100rpx;   
}

map,.mapBox{
  left: 0;
  z-index: 99;
  mix-blend-mode: screen;  
  height: 100rpx;   
}

map,.mapBox{
  width: 750rpx;
  height: 300rpx;
}
.icon {
  width: 1em;
  height: 1em;
  vertical-align: -0.15em;
  fill: currentColor;
  overflow: hidden;
}
</style>
